# Maintainer: Gore Liu <goreliu@126.com>

_realname=jq
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.7.1
pkgrel=3
pkgdesc="Command-line JSON processor (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://jqlang.github.io/jq/'
msys2_repository_url="https://github.com/jqlang/jq"
msys2_references=(
  "cpe: cpe:/a:jq_project:jq"
)
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-oniguruma"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread")
source=("https://github.com/jqlang/${_realname}/releases/download/${_realname}-${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('478c9ca129fd2e3443fe27314b455e211e0d8c60bc8ff7df703873deeee580c2')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  # avoid it asking git for the version
  echo "echo ${pkgver}" > scripts/version
  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --disable-docs

  make
}

check() {
  cd "${srcdir}"/build-${MSYSTEM}
  make check
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  make install DESTDIR="${pkgdir}"
}
